﻿using System;
using System.Collections.Generic;
using System.Text;
using CLoggerNamespace;

namespace HL7v_2x
{
    public class HL7SegmentAL1 :  IHL7Segment
    {
        #region DESARMAR SEGMENTO EN CAMPOS
        public List<HL7Fields> DesarmarSegmentoEnCampos(string strSegment)
        {
            const string strKeyReturn = "<cr>"; //FD

            //EJEMPLO MENSAJE HL7
            /*
             MSH|^~\&|HIG||CPS||20050426113700||ADT^A01^ADT_A01|HIG9744495|P|2.5||||AL<cr>

            EVN|A01|20050426113700||||20050426113700|<cr>


            PID|1||163136^^^^HIG|24957389^^^^DNI|LANE^LUISA||19751128000000|F|||BLANCO ENCALADA 3422 4 C^^||||||||24957389 <cr>

            PV1|1|I|^256^|R||||||M|||A|4|A0|N||VL|H0173963||SI|||||||||||||||||||||||20050426113700 <cr>      
              
            */

            string[] strArrAux = new string[] { };

            List<HL7Fields> lstHL7Fiels = new List<HL7Fields>();

            strArrAux = strSegment.Split('|');


            //int indice=0;
            int y = 0;  //CANTIDAD DE CAMPOS
            int inCantBarras = 0; //CANTIDAD DE BARRAS
            for (int x = 0; x <= strSegment.Length; x++)
            {
                if (strSegment[x] != '|')
                {
                    strArrAux[y] = strArrAux[y] + strSegment[x];
                }
                else
                {
                    inCantBarras++;
                    y++;
                }

            }

            int j = 0;
            foreach (string strField in strArrAux)
            {
                CLogger.Append("Field " + j.ToString() + " : " + strField, CLogger.INFO);
                j++;
            }
            //HL7Fields obj;

            return lstHL7Fiels;

        }

        #endregion
        //public HL7SegmentAL1():base(HL7MessageName.MessageAL1)
        //{

        //}

        //public int BuildFields(byte[] byteInputStreamParam)
        //{
        //    throw new NotImplementedException();
        //}

        //public int BuildFields(byte[] byteInputStreamParam, int intOffset)
        //{
        //    throw new NotImplementedException();
        //}
    }
}
